package com.gxa.controller;

import com.gxa.pojo.Build;
import com.gxa.service.BuildService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Build)表控制层
 *
 * @author makejava
 * @since 2022-09-01 12:38:20
 */
@Api
@RestController
@RequestMapping("build")
public class BuildController {
    /**
     * 服务对象
     */
    @Resource
    private BuildService buildService;

    /**
     * 分页查询
     *
     * @param build 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查找数据并分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildName", value = "楼宇名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildMoney", value = "物业费", dataType = "java.lang.Double", paramType = "body"),
            @ApiImplicitParam(name = "buildArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildManageArea", value = "在管面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildDescribe", value = "描述", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildAddress", value = "地址", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildPhoto", value = "照片", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildNum", value = "层高", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildUnderground", value = "地下楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildOnground", value = "地上楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildCode", value = "编号", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/queryByPage")
    public ResponseData queryByPage(Build build, @ApiParam(value = "页码") int page,@ApiParam(value = "每页多少条") int size) {
        ResponseData data = new ResponseData();
        data.setData( this.buildService.queryByPage( build,page, size));
        return data;
    }

//    /**
//     * 条件查询数据
//     *
//     * @param build 条件
//     * @return 单条数据
//     */
//    @ApiOperation(value = "新增数据")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "buildId", value = "id", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildName", value = "楼宇名称", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildMoney", value = "物业费", dataType = "java.lang.Double", paramType = "body"),
//            @ApiImplicitParam(name = "buildArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
//            @ApiImplicitParam(name = "buildManageArea", value = "在管面积", dataType = "java.lang.Integer", paramType = "body"),
//            @ApiImplicitParam(name = "buildDescribe", value = "描述", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildAddress", value = "地址", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildPhoto", value = "照片", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildNum", value = "层高", dataType = "java.lang.Integer", paramType = "body"),
//            @ApiImplicitParam(name = "buildUnderground", value = "地下楼层", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildOnground", value = "地上楼层", dataType = "java.lang.String", paramType = "body"),
//            @ApiImplicitParam(name = "buildCode", value = "编号", dataType = "java.lang.String", paramType = "body"),
//    })
//    @PostMapping("/query")
//    public ResponseData query(@RequestBody Build build) {
//        ResponseData responseData = new ResponseData();
//        responseData.setData(this.buildService.query(build));
//        return responseData;
//    }

    /**
     * 新增数据
     *
     * @param build 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildName", value = "楼宇名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildMoney", value = "物业费", dataType = "java.lang.Double", paramType = "body"),
            @ApiImplicitParam(name = "buildArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildManageArea", value = "在管面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildDescribe", value = "描述", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildAddress", value = "地址", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildPhoto", value = "照片", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildNum", value = "层高", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildUnderground", value = "地下楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildOnground", value = "地上楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildCode", value = "编号", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/add")
    public ResponseData add(@RequestBody Build build) {
        ResponseData responseData = new ResponseData();
        if (this.buildService.insert(build) > 0) {
            responseData.setCode(200);
            responseData.setMsg("success");
        } else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

    /**
     * 编辑数据
     *
     * @param build 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildName", value = "楼宇名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildMoney", value = "物业费", dataType = "java.lang.Double", paramType = "body"),
            @ApiImplicitParam(name = "buildArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildManageArea", value = "在管面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildDescribe", value = "描述", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildAddress", value = "地址", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildPhoto", value = "照片", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildNum", value = "层高", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildUnderground", value = "地下楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildOnground", value = "地上楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildCode", value = "编号", dataType = "java.lang.String", paramType = "body"),
    })
    @PutMapping("/change")
    public ResponseData edit(@RequestBody Build build) {
        ResponseData responseData = new ResponseData();
        Build update = this.buildService.update(build);
        if (update.equals(null)){
            responseData.setCode(404);
            responseData.setMsg("fail");}else {
            responseData.setCode(200);
            responseData.setData(update);
        }
        return responseData;
    }

    /**
     * 删除数据
     *
     * @param build 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "根据条件删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildName", value = "楼宇名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildMoney", value = "物业费", dataType = "java.lang.Double", paramType = "body"),
            @ApiImplicitParam(name = "buildArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildManageArea", value = "在管面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildDescribe", value = "描述", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildAddress", value = "地址", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildPhoto", value = "照片", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildNum", value = "层高", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "buildUnderground", value = "地下楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildOnground", value = "地上楼层", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "buildCode", value = "编号", dataType = "java.lang.String", paramType = "body"),
    })
    @DeleteMapping("/delete")
    public ResponseData deleteById(@RequestBody Build build) {
        ResponseData responseData = new ResponseData();
        if (this.buildService.deleteById(build)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

}

